Pressidian
花园入口
笔记
项目
关于
实验室
GitHub
花园入口
笔记
项目
关于
实验室
GitHub

KNOWLEDGE PATHS

笔记库
当前位置
笔记库/学习/408/数据结构

3.1 栈

3 分钟阅读 · Note

目录树 578 篇

          • 3.1 栈
          • 4.1 串定义与基本操作
          • 5.1 树
          • 6.1 图的基本概念
          • 7.1 查找的基本概念
          • 8.1 排序基本概念
          • 第二章 线性表
          • 第一章 绪论
      • 论文
    • 笔记目录
    • CLAUDE.md
    • Vue 组件与 Render 函数

关联笔记 6

↗4.1 串定义与基本操作同一路径↗5.1 树同一路径↗6.1 图的基本概念同一路径↗7.1 查找的基本概念同一路径↗8.1 排序基本概念同一路径↗第二章 线性表同一路径
  • 3.1 栈

3.1 栈

3.1.1 栈的基本概念

![Pasted image 20251108164901](../../../_assets/c7c0ce4-Pasted image 20251108164901.png)

![Pasted image 20251108164945](../../../_assets/61e5146-Pasted image 20251108164945.png)

基本操作

![Pasted image 20251108165142](../../../_assets/8157dbc-Pasted image 20251108165142.png)

常考题型

判断出栈顺序是否合法

3.1.2 顺序栈

使用静态数组来实现的栈

初始化

![Pasted image 20251108165443](../../../_assets/0ae9f63-Pasted image 20251108165443.png)

push

![Pasted image 20251108165548](../../../_assets/ba029a9-Pasted image 20251108165548.png)

pop

![Pasted image 20251108165721](../../../_assets/02031e4-Pasted image 20251108165721.png)

获取第一个元素的值

![Pasted image 20251108165833](../../../_assets/fc786b7-Pasted image 20251108165833.png)

共享栈

![Pasted image 20251108170018](../../../_assets/5f4a822-Pasted image 20251108170018.png)

3.1.3 链栈

与单链表一样的操作

3.2 队列

3.2.1 队列的定义

![Pasted image 20251108171112](../../../_assets/011ce54-Pasted image 20251108171112.png)

基本操作

![Pasted image 20251108171158](../../../_assets/33a60de-Pasted image 20251108171158.png)

3.2.2 队列的顺序实现

初始化

![Pasted image 20251108171402](../../../_assets/6cc232f-Pasted image 20251108171402.png) ![Pasted image 20251108171444](../../../_assets/ec67e6a-Pasted image 20251108171444.png)

入队

![Pasted image 20251108171629](../../../_assets/e93cbad-Pasted image 20251108171629.png)

这种方式实现的队列为循环队列: ![Pasted image 20251108171751](../../../_assets/a9e2acb-Pasted image 20251108171751.png) ![Pasted image 20251108171955](../../../_assets/f665503-Pasted image 20251108171955.png)

判空、满

(rear-front+maxsize)%maxsize,也可以使用一个值来存储队列的长度

3.2.3 队列的链式实现

受限的单链表

初始化

![Pasted image 20251108172915](../../../_assets/1d4694f-Pasted image 20251108172915.png)

不带头 ![Pasted image 20251108172938](../../../_assets/83ebb47-Pasted image 20251108172938.png)

插入

![Pasted image 20251108173046](../../../_assets/780b4b9-Pasted image 20251108173046.png)

不带头 ![Pasted image 20251108173144](../../../_assets/15eca48-Pasted image 20251108173144.png)

出队

![Pasted image 20251108173254](../../../_assets/f3ecbab-Pasted image 20251108173254.png)

3.2.4 双端对列

![Pasted image 20251108173710](../../../_assets/33a9128-Pasted image 20251108173710.png)

3.3 栈的应用

3.3.1 括号匹配问题

![Pasted image 20251108175444](../../../_assets/dac69a4-Pasted image 20251108175444.png)

3.3.2 运算表达式求值

![Pasted image 20251108180616](../../../_assets/c14f3b5-Pasted image 20251108180616.png) 中缀表达式的运算顺序可能是不唯一的 ,转化的后准表达式的顺序也可能是不唯一的 ![Pasted image 20251108180916](../../../_assets/44914cd-Pasted image 20251108180916.png) 最好是“左优先”,尽可能的将左侧的运算符优先生效,进而确保算法的确定性。

![Pasted image 20251108181424](../../../_assets/0994d5c-Pasted image 20251108181424.png)

![Pasted image 20251108181711](../../../_assets/b9ec727-Pasted image 20251108181711.png)

![Pasted image 20251108182037](../../../_assets/db94c31-Pasted image 20251108182037.png)

算法实现

![Pasted image 20251108182656](../../../_assets/45a8268-Pasted image 20251108182656.png)

计算中缀表达式: ![Pasted image 20251108183552](../../../_assets/7fc74be-Pasted image 20251108183552.png)

3.3.3 递归调用

![Pasted image 20251108184823](../../../_assets/6515c0c-Pasted image 20251108184823.png) ![Pasted image 20251108185019](../../../_assets/e8c718b-Pasted image 20251108185019.png)

3.3.4 队列应用

树的层次遍历、图的广度优先遍历

3.4 特殊矩阵压缩存储

3.4.1 二维数组

行优先: ![Pasted image 20251109152920](../../../_assets/ead3eed-Pasted image 20251109152920.png)

列优先: ![Pasted image 20251109153000](../../../_assets/34dbe2f-Pasted image 20251109153000.png)

![Pasted image 20251109153141](../../../_assets/cbd3347-Pasted image 20251109153141.png)

3.4.2 对称矩阵

![Pasted image 20251109153339](../../../_assets/f941607-Pasted image 20251109153339.png) ![Pasted image 20251109154023](../../../_assets/1f56db9-Pasted image 20251109154023.png) 将在上三角区的aij转换为aji就可以实现访问上三角区的元素。

3.4.3 三角矩阵

![Pasted image 20251109154347](../../../_assets/a7be067-Pasted image 20251109154347.png)

可以将常量c存于数组末尾: ![Pasted image 20251109155634](../../../_assets/4b65f50-Pasted image 20251109155634.png)

3.4.4 三对角矩阵

![Pasted image 20251109155111](../../../_assets/286be78-Pasted image 20251109155111.png) ![Pasted image 20251109155515](../../../_assets/ce386f6-Pasted image 20251109155515.png)

3.4.5 稀疏矩阵

![Pasted image 20251109160124](../../../_assets/2b0a8ca-Pasted image 20251109160124.png) ![Pasted image 20251109160431](../../../_assets/ac89e26-Pasted image 20251109160431.png)